﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using System.Configuration;
using System.Data.SqlClient;
using Model;
using DBUlitity;

namespace DAL
{
    public class UserLoginDAL
    {
        public static readonly string SqlConnString = ConfigurationManager.ConnectionStrings["ELCO_ConnectionString"].ConnectionString;

        /// <summary>
        /// 读取用户信息
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public static UserInfo GetUserForUName(string uname)
        {
            using (var conn = new SqlConnection(SqlConnString))
            {

                string sql = @" SELECT  userinfo.ID,userinfo.UserNo,userinfo.UserName,userinfo.UserPwd,userinfo.CustomerName,customer.ID as CustomerID from UserInfo  userinfo left join CustomInfo customer on  userinfo.CustomerName = customer.CustomName 
                                    where Lower(userinfo.UserNo)=@user_name;
                                    ";
                UserInfo userinfo = new UserInfo();
                userinfo = conn.Query<UserInfo>(sql, new { user_name = uname.ToLower() }).SingleOrDefault();
                return userinfo;
            }

        }
    }
}
